/// @file Capsule.cpp
/// @brief represent a capsule rigid body

#include "Capsule.h"

#include "ngl/Transformation.h"

Capsule::Capsule() : Particle()
{
    Capsule(0);
}

Capsule::Capsule
            (
                const Capsule& _particle
            ) :
            Particle
            (
                _particle.getId(),
                _particle.getMass(),
                _particle.getPosition(),
                _particle.getColour(),
                _particle.getRadius(),
                _particle.getMoveable()
            )
{
    m_height = _particle.getHeight();

    m_orientationVector = _particle.getOrientationVector();

    m_incrementAngle = _particle.getIncrementAngle();

    m_angle = _particle.getAngle();

    m_initialAngle = _particle.getInitialAngle();
}

Capsule::Capsule
            (
                const int _id,
                const ngl::Real _mass,
                const ngl::Vector _centerPosition,
                const ngl::Colour _colour,
                const ngl::Real _radius,
                const ngl::Real _height,
                const ngl::Vector _orientationVector,
                const ngl::Real _incrementAngle,
                const ngl::Real _initialAngle,
                const bool _moveable
            ) :
            Particle(_id, _mass, _centerPosition, _colour, _radius, _moveable)
{
    //init params
    m_height = _height;

    m_orientationVector = _orientationVector;

    m_incrementAngle = _incrementAngle;

    m_angle = _initialAngle;

    m_initialAngle = _initialAngle;
}

Capsule::~Capsule()
{
}

void Capsule::updateRotation()
{
    //increment angle
    m_angle += m_incrementAngle;

    //convert degrees to radians
    float angle = m_angle * (M_PI / 180.0);

    //calculate new positions following rotations (using pythagoras theorem)
    float x1 = m_position.m_x + cos(angle);
    float z1 = m_position.m_z + sin(angle);

    //set orientation to a normalised vector from centre position to the new position
    m_orientationVector = m_position - ngl::Vector(x1, m_position.m_y, z1);
    m_orientationVector.normalize();
}
